<?php

namespace app\admin\controller;

class Experience extends Base
{
    //留学实况列表
    public function experience()
    {
        $exper = model('common/Experience') -> paginate(5);
        $data = [
            'exper' => $exper
        ];
        $this -> assign($data);
        return view();
    }

    //留学实况添加
    public function experience_add()
    {
        if (request()->isAjax()){
            $data = input('post.');
            $data['img'] = request()-> file('myFile');
            $result = model('common/Experience') -> experience_add($data);
            if ($result == 1){
                $this -> success('添加成功！','admin/experience/experience');
            } else {
                $this -> error($result);
            }
        }
        return view();
    }

    //留学实况编辑
    public function experience_edit()
    {
        if (request()->isAjax()){
            $data = input('post.');
            $data['imgs'] = request()-> file('myFile');
            $result = model('common/Experience') -> experience_edit($data);
            if ($result == 1){
                $this -> success('更新成功！','admin/experience/experience');
            } else {
                $this -> error($result);
            }
        }
        $exper = model('common/Experience') -> find(input('id'));
        $data = [
            'exper' => $exper
        ];
        $this -> assign($data);
        return view();
    }

    //留学实况删除
    public function experience_del()
    {
        if (request()->isAjax()){
            $exper = model('common/Experience') -> find(input('post.id'));
            $result = $exper ->delete();
            if ($result){
                $this -> success('删除成功！','admin/experience/experience');
            } else {
                $this -> error('删除失败！！');
            }
        } else {
            return '非法请求';
        }
    }


}
